import random

import keras.backend.tensorflow_backend as tb
import pandas as pd
from keras.models import load_model

from model.test import fun


def randomChange(num_list):
    res = []
    for i in num_list:
        res.append(i * random.randint(95, 105) / 100)
    return res


def design(item):
    tb._SYMBOLIC_SCOPE.value = True
    global model
    model = load_model('model/selfDesign.h5')
    data = fun(item['country'], item['date'], item['length'], item['director'], item['star1'], item['star2'],
               item['kind'])
    import datetime

    current = datetime.date.today()
    pred = []
    for i in range(1, 21):
        tor = current + datetime.timedelta(days=1)
        pred.append(data)
        data['movie_date'] += 24*3600
    pred = pd.DataFrame(pred).values
    pred = pred.reshape((pred.shape[0], 1, pred.shape[1]))
    res = model.predict(pred).tolist()
    res = [i[0] for i in res]
    return randomChange(res)

